package ptij.vocoder.baseModel.common;

import ptolemy.actor.*;
import ptolemy.kernel.*;
import ptolemy.kernel.util.*;
import ptolemy.data.ObjectToken;
import ptolemy.data.BooleanToken;
import ptolemy.data.expr.Parameter;
import ptolemy.data.type.*;

import ptij.vocoder.baseModel.*;

//////////////////////////////////////////////////////////////////////////
//// SynFilt
/**

@author Ivan Jeukens
@version v 0.1 07/08/2003
*/
public class SynFilt extends TypedAtomicActor {

    public SynFilt(CompositeEntity container, String name) throws
            IllegalActionException, NameDuplicationException {
        super(container, name);

        a = new TypedIOPort(this, "a", true, false);
        a.setTypeEquals(BaseType.OBJECT);

        x = new TypedIOPort(this, "x", true, false);
        x.setTypeEquals(BaseType.OBJECT);

        y = new TypedIOPort(this, "y", false, true);
        y.setTypeEquals(BaseType.OBJECT);
        
        _mem = new Short[Cnst.M];

        update = new Parameter(this, "update", new BooleanToken(true));
    }

    ///////////////////////////////////////////////////////////////////
    ////                     ports and parameters                  ////

    // Input ports
    public TypedIOPort a;
    public TypedIOPort x;

    // Output Ports
    public TypedIOPort y;

    public Parameter update;

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void initialize() throws IllegalActionException {
        super.initialize();
        _init();
    }

    public void fire() throws IllegalActionException {
        ObjectToken obj = (ObjectToken) a.get(0);
        Short [] arg1 = (Short []) obj.getValue();

        obj = (ObjectToken) x.get(0);
        Short [] arg2 = (Short []) obj.getValue();

        Short [] resp = _syn_filt(arg1, arg2);
        obj = new ObjectToken(resp);
        y.broadcast(obj);
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private methods                   ////

    private Short [] _syn_filt(Short [] ap, Short [] x) {
        Short [] y = new Short[Cnst.L_SUBFR];
        
        
        
        
        return y;
    }

    private void _init() {
        for(int i = 0;i < _mem.length;i++) {
            _mem[i] = new Short((short)0);
        }
        
        try {
            BooleanToken bt = (BooleanToken) update.getToken();
            _update = bt.booleanValue();
        }
        catch(IllegalActionException ex) {
            System.out.println(ex);
        }
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private variables                 ////

    private Short [] _mem;
    private boolean _update;
}
